﻿$(function () {
    //fastclick
    Origami.fastclick(document.body);

    if (!NextPage) {
        $('.nomore').show();
    }

    $(window).on('scroll', function () {
        var ScrollTop = $(window).scrollTop();
        var GroupHeight = $('.records-list').height();
        var WinHeight = $(window).height();


        if (ScrollTop + WinHeight + 75 >= GroupHeight && !IsLoading && NextPage && totalCount > 0) {
            Page++;
            GetRecords();
        }

    })
    $('.retry').on('click', function () {
        $(this).hide();
        GetRecords();
    })
    $('.records-list').on('click', '.record-group', function () {
        $(this).find('.new-record').remove();
    })
    function GetRecords() {
        IsLoading = true;
        $('.loading').show()
        $.ajax({
            type: 'POST',
            url: '/customer/queryOrder',
            dataType: 'json',
            data: { page: Page },
            timeout: 10000,
            success: function (result) {
                $('.loading').hide();
                if (result.status == 1) {
                    IsLoading = false;
                    NextPage = result.data.length > 0;
                    if (!NextPage) {
                        $('.nomore').show();
                    }
                    var HTML = '';
                    for (var i in result.data) {
                        HTML += '<a href="' + (detailUrl + '/' + result.data[i].Id) + '">'
                        //if (result.data[i].invalid) {
                        //    HTML += '<div class="record-group invalid">'
                        //} else {
                        HTML += '<div class="record-group">'
                        //}
                        HTML += '<img src="' + result.data[i].ProdIconImg + '">' +
                        '<div class="item-info">';

                        //if (result.records[i].new) {
                        //    HTML += '<h2><i class="new-record"></i><span>' + result.data[i].title + '</span></h2>'
                        //} else {
                        HTML += '<h2><span>' + result.data[i].ProductName + '</span></h2>'
                        //}
                        if (result.data[i].OrderStatus == 0) {
                            HTML += '<p>订单状态：<span style="color: red;">' + result.data[i].OrderStatusText + '</span></p>';

                        }
                        HTML += '</div>' +
                          '</div>' +
                        '</a>';
                    }
                    $('.records-list').append(HTML);
                } else {
                    $('.retry').show();
                }
            },
            error: function () {
                $('.loading').hide();
                $('.retry').show();
            }
        })
    }
});